Search Setup

In this article

POS Search Card

POS search properties

How to: Set up search on the POS

Add a search to a menu button (POS command)

Add a search to the #CURRINPUT

How to: Add Select Trigger for custom tables

Search locally or remotely?

Updating the Index with the Scheduler

Search Syntax

To use a Search Index in the LS Central POS you must create a POS Search Setup. This setup is similar to the POS Lookup Setup where you configure both the graphical (user interface) parts and the functional parts of a POS Search.

A POS Search can be used on the POS by running the SEARCH POS command, or by linking it to a POS Input Control (for example the #CURRINPUT).

  • To set up or edit POS Search, click the icon, enter POS Search List, and select the relevant link.

POS Search Card

POS search properties

Property Description
Interface Profile ID The interface profile that the Search Setup belongs to.
Search ID Identifier for the POS Search Setup.
Description Description for the POS Search Setup.
Default for Function Specifies for which POS Function Mode this search should be used, for example ITEM, CUSTOMER, CARD and so on. This fields must be filled.
Search Index Code Specifies the Search Index Table setup that this POS Search will use. If blank then all Indexed Tables will be used (search will not be filtered to one Search Index Table).
Data Table ID Specifies what POS Data Table to use to present the search result. If blank, then the default #SEARCHRESULT Data Table ID will be used that can show combined results from many Search Index Tables.
Distribution Location If this field contains a Location Code, the POS will call a Web Service function on that location to execute the search. The search results (hits) are returned from the remote location and are used to populate the result Data Set.
POS Search Max Results The maximum number of hits to show.
Confirm Selection A check mark in this field will make the POS ask the user for confirmation before inserting a selected record from the search Data Grid.
Use Wildcard Search (*) If set then wildcards can be used in the search expression (see Search Syntax below).
Use Fuzzy Search(~) If set then fuzzy searches can be used in the search expression (see Search Syntax below).

How to: Set up search on the POS

  1. Define a search index as described in How to: Define a search index for a table.
  2. Open the POS Search List.
  3. Click the New action.
  4. Set the Interface Profile ID, Search ID, and Description.
  5. No more fields needs to be set, optional fields are:
    • Default for Function: Indicates that this search setup should be used for selected function mode.
    • Search Index Code: Only search in selected search index.
    • Data Table ID:
      • If empty, the search setup uses a generic data table.
      • Else, it uses the selected data table to represent the search results. A Search Index Code with the same Table No. must be selected.
    • Distribution Location:
      • If set, the search is performed on the selected location, the same Search Index definition must be on both the current POS and the distributed location.
      • Else, the search is performed on the current service tier.

Add a search to a menu button (POS command)

  1. Open the POS Menu List.
  2. Select a menu to add the search command to, and press Edit.
  3. In the Lines FastTab, add a new line with a description.
  4. Select the SEARCH command in the Command field.
  5. Optionally, set the POS Search ID as the parameter.
    • If no search setup is select, a setup named #DEFAULT is used.

Add a search to the #CURRINPUT

  1. Open the POS Input Control List.
  2. Select the Control ID #CURRINPUT for your interface profile and press edit.
  3. Check the following fields under the General FastTab:
    • Signal Enter Pressed
    • Signal Input Changed
    • Signal As You Type
  4. On the Input Change Search ID field:
    • Either, select a Search Setup from the drill down.
    • Or, put '*' to automatically select a search setup based on the function mode. This option depends on the Default For Function field on the Search Setup.
    • The search becomes disabled if no value is set.

How to: Add Select Trigger for custom tables

Any table can be searched by adding a definition in the Search Index page, but the entries generated from these tables do not necessarily have any trigger associated. A trigger such as:

  • When a user selects an item from the search results it is added to the journal.
  • A customer is selected and it is added to the current transaction.

Triggers for other tables are added with C/AL code, specifically in the POS Transaction codeunit under the ValidateRecordIDInput method.

The method receives a RecordID for the selected entry, the table number is then passed to a C/AL case statement that executes specific code for each table. Add the custom table to the case sentence with the code to be executed on selection. It is recommended to call a custom method that takes in the RecordID of the selected entry and ConfirmSelection (bool) parameters.

Search locally or remotely?

The Search itself can be performed either locally on the POS (on the service tier) or on a selected distributed location. The setup of each is described below.

To search locally

This setup assumes there is a head office where the data is managed (such as items, customers, and so on) and that the data is replicated to the POSs.

  1. Add the following tables to the scheduled list of tables for replication from HO to the POSs.
    • Search Index Action (10000769)
    • Search Index Table (10000766)
    • Search Index Fields (10000767)
  2. On the POS Functionality Profile Card for each POS, select the Update Search Index Automatically check box.
    • When selected, a background process is started after each transaction that monitors the Search Index Action table for changes.

To search on a distributed location

When searching on a distribution location, the POSs will connect through web services to a single location where the search is performed.

For this setup, select head office (HO) to be the distribution location. If another location is selected, all data must be up-to-date and the location should be treated as a local search location (described above).

  1. Add the following tables to the scheduled list of tables for replication from HO to the POSs:
    • Search Index Table (10000766)
    • Search Index Fields (10000767)
  2. On the POS Functionality Profile Card for each POS, clear the Update Search Index Automatically check box.
  3. Change all Search Setups' Distribution Location to point to HO.
    Tip: For advance cases, you can have some searches to be performed locally and some on the distribution location.
  4. Install the service components on HO service tier.
    • Installing the service components will update the search index automatically as soon as the data is updated, for example when an item is updated.

Updating the Index with the Scheduler

For advanced cases it is possible to run a scheduler to update the index from the Search Index Action (10000768) table or re-index everything.

  1. Create a new job with the time it should run.
  2. Add Search Index (10000749) as the codeunit to run.
  3. Either set the code parameters as
    1. UPDATE: To update the index incrementally with changes in the Search Index Action (10000769) table.
    2. INDEX: To re-index everything on each run.

Search Syntax

The Lucene.net search engine supports combining different terms and phrases in its search strings that get interpreted into a Lucene.net Queries.

The following examples demonstrate the search syntax.

Keyword matching

To search in all fields, enter a keyword:

cheese

To search for a phrase, put quotation marks around the phrase:

"gouda cheese"

Keyword matching by field

Search in specific fields by typing the field name followed by a colon (:) and then the keyword you are looking for.

item:milk

Wildcard searches

The single character wildcard search looks for keywords that match that with the single character replaced. For example, to search for "text" or "test" you can use the search:

te?t

Multiple character wildcard searches look for 0 or more characters. For example, to search for "test", "tests", or "tester", you can use the search:

test*

You can also use the wildcard searches in the middle of a keyword.

te*t

Note: You cannot use an asterisk * or a question mark ? as the first character in a search string.

Fuzzy searches

To do a fuzzy search use the tilde character, "~", at the end of a Single word Keyword. For example, to search for a keyword similar in spelling to "frute" use the fuzzy search:

frute~

This search will find keywords like frame and fruit.

An additional (optional) parameter can specify the required similarity. The value is between 0 and 1, with a value closer to 1 only keywords with a higher similarity will be matched. For example:

roam~0.8

The default that is used if the parameter is not given is 0.5.

Proximity searches

To do a proximity search use the tilde character, "~", at the end of a phrase. For example, to search for a "homemade" and "pie" within 10 words of each other in a document use the search:

"homemade pie"~10

Range searches

Range Queries let you match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically.

date_modified:[2002-01-01 TO 2003-01-01]

This will find documents whose date_modified fields have values between 2002-01-01 and 2003-01-01, inclusive. Likewise, to find items on a specified price range:

price:[1 TO 100]

Note: Range Queries are not reserved for date fields. You could also use range queries with non-date fields:

title:{Apple TO Audio}

This will find all documents whose titles are between Apple and Audio, but not including Apple and Audio.

Inclusive range queries are denoted by square brackets. Exclusive range queries are denoted by curly brackets.

Boosting a keyword

To boost a keyword use the caret character, "^", with a boost factor (a number) at the end of the keyword you are searching. The higher the boost factor, the more relevant the keyword will be.

Boosting lets you control the relevance of a document by boosting its keyword. For example, if you are searching for

broccoli apple

and you want the keyword "broccoli" to be more relevant, boost it using the ^ symbol along with the boost factor next to the keyword. You would type:

broccoli^4 apple

This will make documents with the keyword "broccoli" appear more relevant. You can also boost phrases as in the example:

"blue paint"^4 "green paint"

By default, the boost factor is 1. Although the boost factor must be positive, it can be less than 1 (for example 0.2).

Boolean operators

Boolean operators allow keywords to be combined through logic operators. The Search supports AND, "+", OR, NOT, and "-" as Boolean operators. Note: Boolean operators must be ALL CAPS.

OR

The OR operator is the default conjunction operator. This means that if there is no Boolean operator between two keywords, the OR operator is used. The OR operator links two keywords and finds a matching document, if either of the keywords exists in a document. This is equivalent to a union using sets. The symbol || can be used in place of the word OR.

To search for documents that contain either "cheese" or just "milk" use the query:

cheese milk

or

cheese OR milk

AND

The AND operator matches documents where both keywords exist anywhere in the text of a single document. This is equivalent to an intersection using sets. The symbol && can be used in place of the word AND.

To search for documents that contain "white" and "paint" use the query:

white AND paint

+

The "+" or required operator requires that the keyword after the "+" symbol exist somewhere in a the field of a single document.

To search for documents that must contain "milk" and may contain "skim" use the query:

+milk skim

NOT

The NOT operator excludes documents that contain the keyword after NOT. This is equivalent to a difference using sets. The symbol “!” can be used in place of the word NOT.

To search for documents that contain "milk" but not "skim" use the query:

milk NOT skim

Note: The NOT operator cannot be used with just one keyword. For example, the following search will return no results:

NOT "skim milk"

-

The "-" or prohibit operator excludes documents that contain the keyword after the "-" symbol.

To search for documents that contain "water" but not "sparkling" use the query:

water -sparkling

Grouping

Use parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.

To search for either "milk" or "soda" and "0.5 L" use the query:

(milk OR soda) AND "0.5 L"

Field grouping

Use parentheses to group multiple clauses to a single field.

To search for a title that contains both the word "return" and the phrase "pink panther" use the query:

title:(+return +"pink panther")

Escaping special characters

Escaping special characters that are part of the query syntax. The current list special characters are

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \

To escape these character use the \ before the character. For example to search for (1+1):2 use the query:

\(1\+1\)\:2